package com.zeng.sim.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zeng.sim.controller.domain.SimMsgRecord;
import com.zeng.sim.controller.domain.request.PageDomain;
import com.zeng.sim.controller.domain.response.ResultTable;
import com.zeng.sim.mapper.model.SimMsgRecordEntity;
import com.zeng.sim.service.ServerMsgService;
import com.zeng.sim.service.SimMsgRecordService;
import com.zeng.sim.util.SimConstant;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 描述信息
 *
 * @author zengwanlin
 * @date 2023-12-21T13:52
 */
@Controller
@RequestMapping("/server/msg")
public class ServerMsgController {

    @Autowired
    private ServerMsgService serverMsgService;

    @Autowired
    private SimMsgRecordService simMsgRecordService;

    @GetMapping("/list")
    public String list() {
        return "server/msg/list/main";
    }

    @GetMapping("/add")
    public String add(Model model) {
        model.addAttribute("busiType", SimConstant.BUSI_TYPE_02);
        return "server/msg/list/add";
    }

    @GetMapping("/edit")
    public String edit(Model model, String id) {
        SimMsgRecordEntity simMsgRecordEntity = simMsgRecordService.getById(id);
        SimMsgRecord simMsgRecord = new SimMsgRecord();
        BeanUtils.copyProperties(simMsgRecordEntity, simMsgRecord);
        model.addAttribute("simMsgRecord", simMsgRecord);
        return "server/msg/list/edit";
    }

    @GetMapping("/data")
    @ResponseBody
    public ResultTable data(SimMsgRecord msgRecord, PageDomain pageDomain) {
        Page<SimMsgRecord> page = serverMsgService.data(msgRecord, pageDomain);
        return ResultTable.pageTable(page);
    }

}
